const { update, get } = require('../../helper/db');
const { ok, door } = require('../../helper/util');

/**
 * @apiDefine ErrorResponse
 * @apiError (请求错误) {String} err_message 错误信息描述
 */

/**
 * @apiVersion 1.0.0
 * @apiGroup 朋友圈
 * @api {POST} api/moment/del 删除朋友圈
 * @apiName api/moment/del
 * @apiExample {js} axios 例子:
 *  axios.post('http://39.105.38.34:8080/api/moment/del', {
 *    momentID: 1,
 *  });
 * @apiParam  {Number} momentID 朋友圈 ID
 * @apiSuccess (请求成功) {Null} data 删除成功后不返回数据
 * @apiuse  ErrorResponse
 */


module.exports = async ctx => {
  var token = ctx.headers.authorization;
  var params = ctx.request.body;
  var user = await door(token);
  var moment = await get('moments', params.momentID);
  // 软删除朋友圈，将朋友圈状态改为 2
  var moment = await update('moments', { ...moment, status: 2 });

  ctx.body = ok(null);
}
